<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../js/jquery.js"></script>

    <script>
        // Promise的封装
        function request(url) {
            return new Promise((resolve, reject) => {
                $.ajax({
                    url: url,
                    success(data) {
                        resolve(data)
                    },
                    error(err) {
                        reject(err)
                    }
                })
            })
        };
        // 将所有的响应拿到之后,返回结果  放在数组中
        Promise.all([request('http://localhost:3000/data'), request('http://localhost:3000/data1'), request(
                'http://localhost:3000/data2')])
            .then(res => {
                console.log(res);
            });

        Promise.race([request('http://localhost:3000/data'), request('http://localhost:3000/data1'), request(
                'http://localhost:3000/data2')])
            .then(res => {
                console.log(res);
            })
    </script>
</body>

</html>